import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { router } from './router/index.js'
import axios from 'axios'
import { createPinia } from 'pinia'


const app = createApp(App)
const pinia = createPinia()
//添加axios请求的拦截器
axios.interceptors.request.use(config => {
    //从本地读取token
    const token = localStorage.getItem('token')
    //判断token是否存在
    if (token) {
        //将token添加到请求头中
        config.headers.Authorization = `Bearer ${token}`
    }
    return config;
});

app.use(pinia)

app.config.productionTip = false
// 指定 axios 的全局配置，指定为后端服务器地址
axios.defaults.baseURL = 'http://localhost:8081/'
app.config.globalProperties.$axios = axios
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
//使用plus
app.use(ElementPlus)
app.use(router)
app.mount('#app')